import cv2
import json
import imageio_ffmpeg as ffmpeg


class VideoBase:
    def __init__(self, video_path: str):
        """
        video_path: 输入视频路径
        video_name: 输入视频文件名
        """
        self.video_path = video_path
        self._init_info()

    def _init_info(self):
        # 打开视频获取信息
        self.cap = cv2.VideoCapture(self.video_path)
        self.fps = self.cap.get(cv2.CAP_PROP_FPS)  # 每秒帧数
        self.width = int(self.cap.get(cv2.CAP_PROP_FRAME_WIDTH))  # 视频一帧宽
        self.height = int(self.cap.get(cv2.CAP_PROP_FRAME_HEIGHT))  # 视频一帧高
        self.frame_count = int(self.cap.get(cv2.CAP_PROP_FRAME_COUNT))  # 视频总帧数
        self.duration = self.frame_count / self.fps  # 视频总时长

        # FFmpeg 路径
        self.ffmpeg_exe = ffmpeg.get_ffmpeg_exe()
        # self.ffmpeg_exe = "D:/ffmpeg-master-latest-win64-gpl/bin/ffmpeg.exe"
        print(json.dumps(self.__dict__, indent=4, ensure_ascii=False, default=str))


